# -*- coding: utf-8 -*-
import unittest
import os
import sys


class MyTest(unittest.TestCase):

    global case_count
    case_count = 0

    global image_count
    image_count = 0

    def setUp(self):
        print('case ' + str(self.case_id_number()))
        img_id = self.image_id_number()
        self.file_name = img_id + '.png'
        print('image/' + self.file_name)

    # Calculate the number of test cases
    def case_id_number(self):
        global case_count
        case_count += 1
        if case_count <= 9:
            count = "00" + str(case_count)
        elif case_count <= 99:
            count = "0" + str(case_count)
        else:
            count = str(case_count)
        return count

    # Generate a screenshot file name
    def image_id_number(self):
        global image_count
        image_count += 1
        if image_count <= 9:
            count = "00" + str(image_count)
        elif image_count <= 99:
            count = "0" + str(image_count)
        else:
            count = str(image_count)
        return count

    def insert_img(self, driver, file_name):
        base_dir = os.path.dirname(os.path.dirname(__file__))
        fs = os.path.join(base_dir, "reporting/report.txt")
        f = open(fs, 'r')
        report_dir = f.read()
        f.close()
        # print('截图路径文件：', report_dir + "/image/" + file_name)
        driver.get_windows_img(report_dir + "/image/" + file_name)

    def tearDown(self):
        self.insert_img(self.driver, self.file_name)
        self.driver.quit()


if __name__ == '__main__':
    pass
